#!/bin/bash


#################################################
#
#  @author： man deep as the sea
#  @date  :  2021-04-21
#  @desc  :  oms_order 表导入任务
#  @contact: 13813838383388
#
#################################################

export JAVA_HOME=/opt/apps/jdk-11.0.9/
export HIVE_HOME=/opt/apps/hive-3.1.2/
export HADOOP_HOME=/opt/apps/hadoop-3.1.1/ 
export SQOOP_HOME=/opt/apps/sqoop-1.4.7/

dt=`date +%Y-%m-%d`
dt2=`date -d'-1 day' +%Y-%m-%d`

if [ $1 ]
then 
  dt2=$1
  dt=`date -d"${dt2} +1 day" +%Y-%m-%d`
fi  

${SQOOP_HOME}/bin/sqoop import \
--connect jdbc:mysql://hdp01:3306/realtimedw \
--username root \
--password ABC123abc.123 \
--hive-import \
--hive-table doit20ods.oms_order \
--hive-partition-key dt \
--hive-partition-value ${dt2} \
--as-textfile \
--fields-terminated-by ',' \
--compress   \
--compression-codec gzip \
--split-by id \
--null-string '\\N' \
--null-non-string '\\N' \
--hive-overwrite  \
--query "select * from oms_order where modify_time>='${dt2} 00:00:00' and modify_time<'${dt} 00:00:00' and \$CONDITIONS"  \
--target-dir '/user/root/tmp'   \
--delete-target-dir \
-m 2



SQOOP_EXIT_CODE=$?

if [ $SQOOP_EXIT_CODE -eq 0 ] 
then
 echo "恭喜.... 任务执行成功"
else
 echo "节哀顺变.....挂了"
fi

exit $SQOOP_EXIT_CODE






